package com.ruoyi.sycs.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sycs.domain.vo.BsJiancyjVo;
import com.ruoyi.sycs.domain.bo.BsJiancyjBo;
import com.ruoyi.sycs.service.IBsJiancyjService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检测依据设置
 *
 * @author zyb
 * @date 2024-06-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sycs/bsJiancyj")
public class BsJiancyjController extends BaseController {

    private final IBsJiancyjService iBsJiancyjService;

    /**
     * 查询检测依据设置列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<BsJiancyjVo> list(BsJiancyjBo bo, PageQuery pageQuery) {
        return iBsJiancyjService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出检测依据设置列表
     */
    @SaCheckLogin
    @Log(title = "检测依据设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsJiancyjBo bo, HttpServletResponse response) {
        List<BsJiancyjVo> list = iBsJiancyjService.queryList(bo);
        ExcelUtil.exportExcel(list, "检测依据设置", BsJiancyjVo.class, response);
    }

    /**
     * 获取检测依据设置详细信息
     *
     * @param jiancyjId 主键
     */
    @SaCheckLogin
    @GetMapping("/{jiancyjId}")
    public R<BsJiancyjVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long jiancyjId) {
        return R.ok(iBsJiancyjService.queryById(jiancyjId));
    }

    /**
     * 新增检测依据设置
     */
    @SaCheckLogin
    @Log(title = "检测依据设置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BsJiancyjBo bo) {
        return toAjax(iBsJiancyjService.insertByBo(bo));
    }

    /**
     * 修改检测依据设置
     */
    @SaCheckLogin
    @Log(title = "检测依据设置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BsJiancyjBo bo) {
        return toAjax(iBsJiancyjService.updateByBo(bo));
    }

    /**
     * 删除检测依据设置
     *
     * @param jiancyjIds 主键串
     */
    @SaCheckLogin
    @Log(title = "检测依据设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jiancyjIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] jiancyjIds) {
        return toAjax(iBsJiancyjService.deleteWithValidByIds(Arrays.asList(jiancyjIds), true));
    }
}
